# 关闭集群
for file in `ls ./release`
do
    if [ $file ]; then
        echo "STOP ==> ./release/"$file
        cd ./release/$file/bin && ./stop.sh full && cd - > /dev/null
    fi
done

# 停止并删除msyql容器
docker stop $(docker ps -q -f name=VM-GO)
docker rm $(docker ps -aq -f name=VM-GO)
docker stop mysql_node_1
docker stop mysql_node_2
docker stop mysql_node_3
docker stop mysql_node_4
docker rm mysql_node_1
docker rm mysql_node_2
docker rm mysql_node_3
docker rm mysql_node_4
rm -rf ./mysql/data1/*
rm -rf ./mysql/data2/*
rm -rf ./mysql/data3/*
rm -rf ./mysql/data4/*

# 清空集群
for file in `ls ./release`
do
    if [ $file ]; then
        echo "Clear ==> ./release/"$file
        rm -rf ./release/$file/data
        rm -rf ./release/$file/log/*
    fi
done

# 重启启动
docker run --name mysql_node_1 -d -p 6606:3306 -e MYSQL_ROOT_PASSWORD=root -v ./mysql/data1:/var/lib/mysql mysql
docker run --name mysql_node_2 -d -p 6607:3306 -e MYSQL_ROOT_PASSWORD=root -v ./mysql/data2:/var/lib/mysql mysql
docker run --name mysql_node_3 -d -p 6608:3306 -e MYSQL_ROOT_PASSWORD=root -v ./mysql/data3:/var/lib/mysql mysql
docker run --name mysql_node_4 -d -p 6609:3306 -e MYSQL_ROOT_PASSWORD=root -v ./mysql/data4:/var/lib/mysql mysql

echo "Waiting ==> DB init..."
sleep 60

for file in `ls ./release`
do
    if [ $file ]; then
        echo "START ==> ./release/"$file
        cd ./release/$file/bin && ./start.sh -f full && cd - > /dev/null
    fi
done

echo "Waiting ==> Service start..."
sleep 5

netstat -lptn | grep 1230